﻿/**************************************************************************
**
**  MisCip
**  ~~~~~~~~~~
**
**  FormRefresh.cs: 
**  ---------
**  Aktualisiert die Anzeige des Hauptfensters
**
**  
**************************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;

namespace Pic_Simulator
{
    public partial class MisCip : Form
    {

        /*********************************************************************/
        /**   updateStatus_Click
        **
        **  Ein Klick auf ein Bit im Status-Register wird registriert
        **
        **  Ret: void
        **
        **************************************************************************/

        private delegate void updateStatus_ClickDelegate(object sender, EventArgs e);
        private void updateStatus_Click(object sender, EventArgs e)
        {
            if (InvokeRequired)
            {
                var invokeVar = new updateStatus_ClickDelegate(updateStatus_Click);
                Invoke(invokeVar);
            }
            else
            {
                Control ctrl = (Control)sender;
                if (ctrl.Text == "0")
                {
                    ctrl.Text = "1";
                }
                else
                {
                    ctrl.Text = "0";
                }

                string statusReg = tStatus7.Text +
                                   tStatus6.Text +
                                   tStatus5.Text +
                                   tStatus4.Text +
                                   tStatus3.Text +
                                   tStatus2.Text +
                                   tStatus1.Text +
                                   tStatus0.Text;
                statusReg.PadLeft(2, '0');
                iReg[0x03] = Convert.ToInt32(statusReg, 2);
                iReg[0x83] = iReg[0x03];

                listCode.Focus();

                refreshReg();
            }
        }

        /*********************************************************************/
        /**   updateTrisA_Click
        **
        **  Ein Klick auf ein Bit im TRISA-Register wird registriert
        **
        **  Ret: void
        **
        **************************************************************************/

        private delegate void updateTrisA_ClickDelegate(object sender, EventArgs e);
        private void updateTrisA_Click(object sender, EventArgs e)
        {
            if (InvokeRequired)
            {
                var invokeVar = new updateTrisA_ClickDelegate(updateTrisA_Click);
                Invoke(invokeVar);
            }
            else
            {
                Control ctrl = (Control)sender;
                if (ctrl.Text == "o")
                {
                    ctrl.Text = "i";
                }
                else
                {
                    ctrl.Text = "o";
                }
                
                //String trisAReg;
                string trisAReg  = tbTrisA4.Text +
                                   tbTrisA3.Text +
                                   tbTrisA2.Text +
                                   tbTrisA1.Text +
                                   tbTrisA0.Text;

                trisAReg = trisAReg.Replace("o", "0");
                trisAReg = trisAReg.Replace("i", "1");
                trisAReg.PadLeft(2, '0');
                iReg[0x85] = Convert.ToInt32(trisAReg, 2);

                listCode.Focus();

                refreshReg();
            }
        }
        private delegate void cbDelay_SelectedIndexChangedDelegate(object sender, EventArgs e);
        private void cbDelay_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (InvokeRequired)
            {
                var invokeVar = new cbDelay_SelectedIndexChangedDelegate(cbDelay_SelectedIndexChanged);
                Invoke(invokeVar);
            }
            else
            {
                iDelay = Convert.ToInt32(cbDelay.SelectedItem);
            }
        }

        /*********************************************************************/
        /**   updateTrisB_Click
        **
        **  Ein Klick auf ein Bit im TRISB-Register wird registriert
        **
        **  Ret: void
        **
        **************************************************************************/

        private delegate void updateTrisB_ClickDelegate(object sender, EventArgs e);
        private void updateTrisB_Click(object sender, EventArgs e)
        {
            if (InvokeRequired)
            {
                var invokeVar = new updateTrisB_ClickDelegate(updateTrisB_Click);
                Invoke(invokeVar);
            }
            else
            {
                Control ctrl = (Control)sender;
                if (ctrl.Text == "o")
                {
                    ctrl.Text = "i";
                }
                else
                {
                    ctrl.Text = "o";
                }

                string trisBReg = tbTrisB7.Text +
                                   tbTrisB6.Text +
                                   tbTrisB5.Text +
                                   tbTrisB4.Text +
                                   tbTrisB3.Text +
                                   tbTrisB2.Text +
                                   tbTrisB1.Text +
                                   tbTrisB0.Text;
                trisBReg = trisBReg.Replace("o", "0");
                trisBReg = trisBReg.Replace("i", "1");
                trisBReg.PadLeft(2, '0');
                iReg[0x86] = Convert.ToInt32(trisBReg, 2);

                listCode.Focus();

                refreshReg();
            }
        }

        /*********************************************************************/
        /**   registryChanged
        **
        **  Ein Klick auf ein Bit im PortRA-Register wird registriert
        **
        **  Ret: void
        **
        **************************************************************************/

        private delegate void portRA_ClickDelegate(object sender, EventArgs e);
        private void portRA_Click(object sender, EventArgs e)
        {
            if (InvokeRequired)
            {
                var invokeVar = new portRA_ClickDelegate(updateStatus_Click);
                Invoke(invokeVar);
            }
            else
            {
                Control ctrl = (Control)sender;
                if (ctrl.Text == "0")
                {
                    ctrl.Text = "1";
                }
                else
                {
                    ctrl.Text = "0";
                }

                string portRA = tRA4.Text +
                                tRA3.Text +
                                tRA2.Text +
                                tRA1.Text +
                                tRA0.Text;
                portRA.PadLeft(2, '0');
                iReg[0x05] = Convert.ToInt32(portRA, 2);
                listCode.Focus();

                refreshReg();
            }
        }

        /*********************************************************************/
        /**   registryChanged
        **
        **  Wenn ein Wert in der Registry geändert wurde, wird der in der Registry übernommen
        **
        **  Ret: void
        **
        **************************************************************************/

        private delegate void registryChangedDelegate(object sender, KeyPressEventArgs e);
        private void registryChanged(object sender, KeyPressEventArgs e)
        {
            if (InvokeRequired)
            {
                var invokeHelper = new registryChangedDelegate(registryChanged);
                Invoke(invokeHelper, sender, e);
            }
            else
            {
                if (e.KeyChar == 13)
                {
                    try
                    {
                        Control ctrl = (Control)sender;
                        listCode.Focus();
                        
                        int iValue = Convert.ToInt32(ctrl.Text, 16);
                        int iRegAdress = Convert.ToInt32(ctrl.Name.Remove(0, 5));

                        if (iRegAdress == 0x05 || iRegAdress == 0x0A || iRegAdress == 0x85 || iRegAdress == 0x88 || iRegAdress == 0x8A)
                        {
                            if (iValue >= 0x00 && iValue <= 0x1F)
                            {
                                iReg[iRegAdress] = iValue;
                                refreshReg();
                            }
                            else
                            {
                                refreshReg();
                                MessageBox.Show("Es sind nur Hex-Werte von 0 bis 1F in diesem Register erlaubt!", "Falsche Eingabe", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }

                        else
                        {
                            if(iValue >= 0x00 && iValue <= 0xFF)
                            {
                                iReg[iRegAdress] = iValue;
                                refreshReg();
                            }
                            else
                            {
                                refreshReg();
                                MessageBox.Show("Es sind nur Hex-Werte von 0 bis FF in diesem Register erlaubt!", "Falsche Eingabe", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        refreshReg();
                        MessageBox.Show("Es sind nur Hex-Werte von 0 bis FF in diesem Register erlaubt!", "Falsche Eingabe", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }

        /*********************************************************************/
        /**   portRB_Click
        **
        **  Ein Klick auf ein Bit im PortRB-Register wird registriert
        **
        **  Ret: void
        **
        **************************************************************************/

        private delegate void portRB_ClickDelegate(object sender, EventArgs e);
        private void portRB_Click(object sender, EventArgs e)
        {
            if (InvokeRequired)
            {
                var invokeVar = new portRB_ClickDelegate(updateStatus_Click);
                Invoke(invokeVar);
            }
            else
            {
                Control ctrl = (Control)sender;
                if (ctrl.Text == "0")
                {
                    ctrl.Text = "1";
                }
                else
                {
                    ctrl.Text = "0";
                }

                string portRB = tRB7.Text +
                                tRB6.Text +
                                tRB5.Text +
                                tRB4.Text +
                                tRB3.Text +
                                tRB2.Text +
                                tRB1.Text +
                                tRB0.Text;
                portRB.PadLeft(2, '0');
                iReg[0x06] = Convert.ToInt32(portRB, 2);

                listCode.Focus();

                refreshReg();
            }
        }

        /*********************************************************************/
        /**   updateOptionReg_Click
        **
        **  Ein Klick auf ein Bit im Option-Register wird registriert
        **
        **  Ret: void
        **
        **************************************************************************/

        private delegate void updateOptionReg_ClickkDelegate(object sender, EventArgs e);
        private void updateOptionReg_Click(object sender, EventArgs e)
        {
            if (InvokeRequired)
            {
                var invokeVar = new updateOptionReg_ClickkDelegate(updateOptionReg_Click);
                Invoke(invokeVar);
            }
            else
            {
                Control ctrl = (Control)sender;
                if (ctrl.Text == "0")
                {
                    ctrl.Text = "1";
                }
                else
                {
                    ctrl.Text = "0";
                }

                string OptionReg = tbOption7.Text +
                                   tbOption6.Text +
                                   tbOption5.Text +
                                   tbOption4.Text +
                                   tbOption3.Text +
                                   tbOption2.Text +
                                   tbOption1.Text +
                                   tbOption0.Text;
                OptionReg.PadLeft(2, '0');
                iReg[0x81] = Convert.ToInt32(OptionReg, 2);

                listCode.Focus();

                refreshReg();
            }
        }

        /*********************************************************************/
        /**   updateIntReg_Click
        **
        **  Ein Klick auf ein Bit im INTCON-Register wird registriert
        **
        **  Ret: void
        **
        **************************************************************************/

        private delegate void updateIntReg_ClickkDelegate(object sender, EventArgs e);
        private void updateIntReg_Click(object sender, EventArgs e)
        {
            if (InvokeRequired)
            {
                var invokeVar = new updateIntReg_ClickkDelegate(updateIntReg_Click);
                Invoke(invokeVar);
            }
            else
            {
                Control ctrl = (Control)sender;
                if (ctrl.Text == "0")
                {
                    ctrl.Text = "1";
                }
                else
                {
                    ctrl.Text = "0";
                }

                string IntReg = tbInt7.Text +
                                tbInt6.Text +
                                tbInt5.Text +
                                tbInt4.Text +
                                tbInt3.Text +
                                tbInt2.Text +
                                tbInt1.Text +
                                tbInt0.Text;
                IntReg.PadLeft(2, '0');
                iReg[0xB] = Convert.ToInt32(IntReg, 2);
                iReg[0x8B] = iReg[0xB];

                listCode.Focus();

                refreshReg();
            }
        }

        /*********************************************************************/
        /**   updateSerielCon
        **
        **  Setzt die Serialverbindung mit deren zugehörigen Port
        **
        **  Ret: void
        **
        **************************************************************************/

        private delegate void updateSerielConDelegate(object sender, EventArgs e);
        private void updateSerielCon(object sender, EventArgs e)
        {
            if (InvokeRequired)
            {
                var invokeVar = new updateSerielConDelegate(updateSerielCon);
                Invoke(invokeVar);
            }
            else
            {
                if (bSerialCon)
                {
                    bSerialCon = false;
                    tbSerialState.Text = "OFF";
                    tbSerialState.BackColor = Color.Red;
                }
                else
                {
                    bSerialCon = true;
                    tbSerialState.Text = "ON";
                    tbSerialState.BackColor = Color.Green;
                }
                listCode.Focus();
            }
        }

        /*********************************************************************/
        /**   updateWatchDog
        **
        **  Schaltet den Watchdog an oder aus
        **
        **  Ret: void
        **
        **************************************************************************/

        private delegate void updateWatchDogDelegate(object sender, EventArgs e);
        private void updateWatchDog(object sender, EventArgs e)
        {
            if (InvokeRequired)
            {
                var invokeVar = new updateWatchDogDelegate(updateWatchDog);
                Invoke(invokeVar);
            }
            else
            {
                if (bWatchdog)
                {
                    bWatchdog = false;
                    tbWatchDogSw.Text = "OFF";
                    tbWatchDogSw.BackColor = Color.Red;
                }
                else
                {
                    bWatchdog = true;
                    tbWatchDogSw.Text = "ON";
                    tbWatchDogSw.BackColor = Color.Green;
                }
                listCode.Focus();
            }
        }

        /*********************************************************************/
        /**   updateEECONReg_Click
        **
        **  Ein Klick auf ein Bit im EECON1-Register wird registriert
        **
        **  Ret: void
        **
        **************************************************************************/

        private delegate void updateEECONReg_ClickDelegate(object sender, EventArgs e);
        private void updateEECONReg_Click(object sender, EventArgs e)
        {
            if (InvokeRequired)
            {
                var invokeVar = new updateEECONReg_ClickDelegate(updateEECONReg_Click);
                Invoke(invokeVar);
            }
            else
            {
                Control ctrl = (Control)sender;
                if (ctrl.Text == "0")
                {
                    ctrl.Text = "1";
                }
                else
                {
                    ctrl.Text = "0";
                }

                string EECONReg =  tbEECON4.Text +
                                   tbEECON3.Text +
                                   tbEECON2.Text +
                                   tbEECON1.Text +
                                   tbEECON0.Text;
                EECONReg.PadLeft(2, '0');
                iReg[0x88] = Convert.ToInt32(EECONReg, 2);

                listCode.Focus();

                refreshReg();
            }
        }

        /*********************************************************************/
        /**   refreshReg
        **
        **  Aktualisiert alle Registerfelder auf der GUI sowie den Stack
        **
        **  Ret: void
        **
        **************************************************************************/

        private delegate void refreshRegkDelegate();
        private void refreshReg()
        {
            if (InvokeRequired)
            {
                var invokeVar = new refreshRegkDelegate(refreshReg);
                Invoke(invokeVar);
            }
            tbWReg.Text = iWReg.ToString("X").PadLeft(2, '0');   //W-Register aktualisieren
            tbPC.Text = iPC.ToString("X").PadLeft(2, '0');    //Programmcounter
            tblCycles.Text = lCycles.ToString("D").PadLeft(2, '0');    //Zyklen            
            tbRuntime.Text = lRuntime.ToString("D").PadLeft(2, '0');   //Laufzeitzähler
            tbWatchdog.Text = lWatchdog.ToString("D").PadLeft(2, '0'); //Watchdog
            tbReg000.Text = iReg[0].ToString("X").PadLeft(2, '0');
            tbReg001.Text = iReg[1].ToString("X").PadLeft(2, '0');
            tbReg002.Text = iReg[2].ToString("X").PadLeft(2, '0');
            tbReg003.Text = iReg[3].ToString("X").PadLeft(2, '0');
            tbReg004.Text = iReg[4].ToString("X").PadLeft(2, '0');
            tbReg005.Text = iReg[5].ToString("X").PadLeft(2, '0');
            tbReg006.Text = iReg[6].ToString("X").PadLeft(2, '0');
            tbReg007.Text = iReg[7].ToString("X").PadLeft(2, '0');
            tbReg008.Text = iReg[8].ToString("X").PadLeft(2, '0');
            tbReg009.Text = iReg[9].ToString("X").PadLeft(2, '0');
            tbReg010.Text = iReg[10].ToString("X").PadLeft(2, '0');
            tbReg011.Text = iReg[11].ToString("X").PadLeft(2, '0');
            tbReg012.Text = iReg[12].ToString("X").PadLeft(2, '0');
            tbReg013.Text = iReg[13].ToString("X").PadLeft(2, '0');
            tbReg014.Text = iReg[14].ToString("X").PadLeft(2, '0');
            tbReg015.Text = iReg[15].ToString("X").PadLeft(2, '0');
            tbReg016.Text = iReg[16].ToString("X").PadLeft(2, '0');
            tbReg017.Text = iReg[17].ToString("X").PadLeft(2, '0');
            tbReg018.Text = iReg[18].ToString("X").PadLeft(2, '0');
            tbReg019.Text = iReg[19].ToString("X").PadLeft(2, '0');
            tbReg020.Text = iReg[20].ToString("X").PadLeft(2, '0');
            tbReg021.Text = iReg[21].ToString("X").PadLeft(2, '0');
            tbReg022.Text = iReg[22].ToString("X").PadLeft(2, '0');
            tbReg023.Text = iReg[23].ToString("X").PadLeft(2, '0');
            tbReg024.Text = iReg[24].ToString("X").PadLeft(2, '0');
            tbReg025.Text = iReg[25].ToString("X").PadLeft(2, '0');
            tbReg026.Text = iReg[26].ToString("X").PadLeft(2, '0');
            tbReg027.Text = iReg[27].ToString("X").PadLeft(2, '0');
            tbReg028.Text = iReg[28].ToString("X").PadLeft(2, '0');
            tbReg029.Text = iReg[29].ToString("X").PadLeft(2, '0');
            tbReg030.Text = iReg[30].ToString("X").PadLeft(2, '0');
            tbReg031.Text = iReg[31].ToString("X").PadLeft(2, '0');
            tbReg032.Text = iReg[32].ToString("X").PadLeft(2, '0');
            tbReg033.Text = iReg[33].ToString("X").PadLeft(2, '0');
            tbReg034.Text = iReg[34].ToString("X").PadLeft(2, '0');
            tbReg035.Text = iReg[35].ToString("X").PadLeft(2, '0');
            tbReg036.Text = iReg[36].ToString("X").PadLeft(2, '0');
            tbReg037.Text = iReg[37].ToString("X").PadLeft(2, '0');
            tbReg038.Text = iReg[38].ToString("X").PadLeft(2, '0');
            tbReg039.Text = iReg[39].ToString("X").PadLeft(2, '0');
            tbReg040.Text = iReg[40].ToString("X").PadLeft(2, '0');
            tbReg041.Text = iReg[41].ToString("X").PadLeft(2, '0');
            tbReg042.Text = iReg[42].ToString("X").PadLeft(2, '0');
            tbReg043.Text = iReg[43].ToString("X").PadLeft(2, '0');
            tbReg044.Text = iReg[44].ToString("X").PadLeft(2, '0');
            tbReg045.Text = iReg[45].ToString("X").PadLeft(2, '0');
            tbReg046.Text = iReg[46].ToString("X").PadLeft(2, '0');
            tbReg047.Text = iReg[47].ToString("X").PadLeft(2, '0');
            tbReg048.Text = iReg[48].ToString("X").PadLeft(2, '0');
            tbReg049.Text = iReg[49].ToString("X").PadLeft(2, '0');
            tbReg050.Text = iReg[50].ToString("X").PadLeft(2, '0');
            tbReg051.Text = iReg[51].ToString("X").PadLeft(2, '0');
            tbReg052.Text = iReg[52].ToString("X").PadLeft(2, '0');
            tbReg053.Text = iReg[53].ToString("X").PadLeft(2, '0');
            tbReg054.Text = iReg[54].ToString("X").PadLeft(2, '0');
            tbReg055.Text = iReg[55].ToString("X").PadLeft(2, '0');
            tbReg056.Text = iReg[56].ToString("X").PadLeft(2, '0');
            tbReg057.Text = iReg[57].ToString("X").PadLeft(2, '0');
            tbReg058.Text = iReg[58].ToString("X").PadLeft(2, '0');
            tbReg059.Text = iReg[59].ToString("X").PadLeft(2, '0');
            tbReg060.Text = iReg[60].ToString("X").PadLeft(2, '0');
            tbReg061.Text = iReg[61].ToString("X").PadLeft(2, '0');
            tbReg062.Text = iReg[62].ToString("X").PadLeft(2, '0');
            tbReg063.Text = iReg[63].ToString("X").PadLeft(2, '0');
            tbReg064.Text = iReg[64].ToString("X").PadLeft(2, '0');
            tbReg065.Text = iReg[65].ToString("X").PadLeft(2, '0');
            tbReg066.Text = iReg[66].ToString("X").PadLeft(2, '0');
            tbReg067.Text = iReg[67].ToString("X").PadLeft(2, '0');
            tbReg068.Text = iReg[68].ToString("X").PadLeft(2, '0');
            tbReg069.Text = iReg[69].ToString("X").PadLeft(2, '0');
            tbReg070.Text = iReg[70].ToString("X").PadLeft(2, '0');
            tbReg071.Text = iReg[71].ToString("X").PadLeft(2, '0');
            tbReg072.Text = iReg[72].ToString("X").PadLeft(2, '0');
            tbReg073.Text = iReg[73].ToString("X").PadLeft(2, '0');
            tbReg074.Text = iReg[74].ToString("X").PadLeft(2, '0');
            tbReg075.Text = iReg[75].ToString("X").PadLeft(2, '0');
            tbReg076.Text = iReg[76].ToString("X").PadLeft(2, '0');
            tbReg077.Text = iReg[77].ToString("X").PadLeft(2, '0');
            tbReg078.Text = iReg[78].ToString("X").PadLeft(2, '0');
            tbReg079.Text = iReg[79].ToString("X").PadLeft(2, '0');
            tbReg080.Text = iReg[80].ToString("X").PadLeft(2, '0');
            tbReg081.Text = iReg[81].ToString("X").PadLeft(2, '0');
            tbReg082.Text = iReg[82].ToString("X").PadLeft(2, '0');
            tbReg083.Text = iReg[83].ToString("X").PadLeft(2, '0');
            tbReg084.Text = iReg[84].ToString("X").PadLeft(2, '0');
            tbReg085.Text = iReg[85].ToString("X").PadLeft(2, '0');
            tbReg086.Text = iReg[86].ToString("X").PadLeft(2, '0');
            tbReg087.Text = iReg[87].ToString("X").PadLeft(2, '0');
            tbReg088.Text = iReg[88].ToString("X").PadLeft(2, '0');
            tbReg089.Text = iReg[89].ToString("X").PadLeft(2, '0');
            tbReg090.Text = iReg[90].ToString("X").PadLeft(2, '0');
            tbReg091.Text = iReg[91].ToString("X").PadLeft(2, '0');
            tbReg092.Text = iReg[92].ToString("X").PadLeft(2, '0');
            tbReg093.Text = iReg[93].ToString("X").PadLeft(2, '0');
            tbReg094.Text = iReg[94].ToString("X").PadLeft(2, '0');
            tbReg095.Text = iReg[95].ToString("X").PadLeft(2, '0');
            tbReg096.Text = iReg[96].ToString("X").PadLeft(2, '0');
            tbReg097.Text = iReg[97].ToString("X").PadLeft(2, '0');
            tbReg098.Text = iReg[98].ToString("X").PadLeft(2, '0');
            tbReg099.Text = iReg[99].ToString("X").PadLeft(2, '0');
            tbReg100.Text = iReg[100].ToString("X").PadLeft(2, '0');
            tbReg101.Text = iReg[101].ToString("X").PadLeft(2, '0');
            tbReg102.Text = iReg[102].ToString("X").PadLeft(2, '0');
            tbReg103.Text = iReg[103].ToString("X").PadLeft(2, '0');
            tbReg104.Text = iReg[104].ToString("X").PadLeft(2, '0');
            tbReg105.Text = iReg[105].ToString("X").PadLeft(2, '0');
            tbReg106.Text = iReg[106].ToString("X").PadLeft(2, '0');
            tbReg107.Text = iReg[107].ToString("X").PadLeft(2, '0');
            tbReg108.Text = iReg[108].ToString("X").PadLeft(2, '0');
            tbReg109.Text = iReg[109].ToString("X").PadLeft(2, '0');
            tbReg110.Text = iReg[110].ToString("X").PadLeft(2, '0');
            tbReg111.Text = iReg[111].ToString("X").PadLeft(2, '0');
            tbReg112.Text = iReg[112].ToString("X").PadLeft(2, '0');
            tbReg113.Text = iReg[113].ToString("X").PadLeft(2, '0');
            tbReg114.Text = iReg[114].ToString("X").PadLeft(2, '0');
            tbReg115.Text = iReg[115].ToString("X").PadLeft(2, '0');
            tbReg116.Text = iReg[116].ToString("X").PadLeft(2, '0');
            tbReg117.Text = iReg[117].ToString("X").PadLeft(2, '0');
            tbReg118.Text = iReg[118].ToString("X").PadLeft(2, '0');
            tbReg119.Text = iReg[119].ToString("X").PadLeft(2, '0');
            tbReg120.Text = iReg[120].ToString("X").PadLeft(2, '0');
            tbReg121.Text = iReg[121].ToString("X").PadLeft(2, '0');
            tbReg122.Text = iReg[122].ToString("X").PadLeft(2, '0');
            tbReg123.Text = iReg[123].ToString("X").PadLeft(2, '0');
            tbReg124.Text = iReg[124].ToString("X").PadLeft(2, '0');
            tbReg125.Text = iReg[125].ToString("X").PadLeft(2, '0');
            tbReg126.Text = iReg[126].ToString("X").PadLeft(2, '0');
            tbReg127.Text = iReg[127].ToString("X").PadLeft(2, '0');
            tbReg128.Text = iReg[128].ToString("X").PadLeft(2, '0');
            tbReg129.Text = iReg[129].ToString("X").PadLeft(2, '0');
            tbReg130.Text = iReg[130].ToString("X").PadLeft(2, '0');
            tbReg131.Text = iReg[131].ToString("X").PadLeft(2, '0');
            tbReg132.Text = iReg[132].ToString("X").PadLeft(2, '0');
            tbReg133.Text = iReg[133].ToString("X").PadLeft(2, '0');
            tbReg134.Text = iReg[134].ToString("X").PadLeft(2, '0');
            tbReg135.Text = iReg[135].ToString("X").PadLeft(2, '0');
            tbReg136.Text = iReg[136].ToString("X").PadLeft(2, '0');
            tbReg137.Text = iReg[137].ToString("X").PadLeft(2, '0');
            tbReg138.Text = iReg[138].ToString("X").PadLeft(2, '0');
            tbReg139.Text = iReg[139].ToString("X").PadLeft(2, '0');
            tbReg140.Text = iReg[140].ToString("X").PadLeft(2, '0');
            tbReg141.Text = iReg[141].ToString("X").PadLeft(2, '0');
            tbReg142.Text = iReg[142].ToString("X").PadLeft(2, '0');
            tbReg143.Text = iReg[143].ToString("X").PadLeft(2, '0');
            tbReg144.Text = iReg[144].ToString("X").PadLeft(2, '0');
            tbReg145.Text = iReg[145].ToString("X").PadLeft(2, '0');
            tbReg146.Text = iReg[146].ToString("X").PadLeft(2, '0');
            tbReg147.Text = iReg[147].ToString("X").PadLeft(2, '0');
            tbReg148.Text = iReg[148].ToString("X").PadLeft(2, '0');
            tbReg149.Text = iReg[149].ToString("X").PadLeft(2, '0');
            tbReg150.Text = iReg[150].ToString("X").PadLeft(2, '0');
            tbReg151.Text = iReg[151].ToString("X").PadLeft(2, '0');
            tbReg152.Text = iReg[152].ToString("X").PadLeft(2, '0');
            tbReg153.Text = iReg[153].ToString("X").PadLeft(2, '0');
            tbReg154.Text = iReg[154].ToString("X").PadLeft(2, '0');
            tbReg155.Text = iReg[155].ToString("X").PadLeft(2, '0');
            tbReg156.Text = iReg[156].ToString("X").PadLeft(2, '0');
            tbReg157.Text = iReg[157].ToString("X").PadLeft(2, '0');
            tbReg158.Text = iReg[158].ToString("X").PadLeft(2, '0');
            tbReg159.Text = iReg[159].ToString("X").PadLeft(2, '0');
            tbReg160.Text = iReg[160].ToString("X").PadLeft(2, '0');
            tbReg161.Text = iReg[161].ToString("X").PadLeft(2, '0');
            tbReg162.Text = iReg[162].ToString("X").PadLeft(2, '0');
            tbReg163.Text = iReg[163].ToString("X").PadLeft(2, '0');
            tbReg164.Text = iReg[164].ToString("X").PadLeft(2, '0');
            tbReg165.Text = iReg[165].ToString("X").PadLeft(2, '0');
            tbReg166.Text = iReg[166].ToString("X").PadLeft(2, '0');
            tbReg167.Text = iReg[167].ToString("X").PadLeft(2, '0');
            tbReg168.Text = iReg[168].ToString("X").PadLeft(2, '0');
            tbReg169.Text = iReg[169].ToString("X").PadLeft(2, '0');
            tbReg170.Text = iReg[170].ToString("X").PadLeft(2, '0');
            tbReg171.Text = iReg[171].ToString("X").PadLeft(2, '0');
            tbReg172.Text = iReg[172].ToString("X").PadLeft(2, '0');
            tbReg173.Text = iReg[173].ToString("X").PadLeft(2, '0');
            tbReg174.Text = iReg[174].ToString("X").PadLeft(2, '0');
            tbReg175.Text = iReg[175].ToString("X").PadLeft(2, '0');
            tbReg176.Text = iReg[176].ToString("X").PadLeft(2, '0');
            tbReg177.Text = iReg[177].ToString("X").PadLeft(2, '0');
            tbReg178.Text = iReg[178].ToString("X").PadLeft(2, '0');
            tbReg179.Text = iReg[179].ToString("X").PadLeft(2, '0');
            tbReg180.Text = iReg[180].ToString("X").PadLeft(2, '0');
            tbReg181.Text = iReg[181].ToString("X").PadLeft(2, '0');
            tbReg182.Text = iReg[182].ToString("X").PadLeft(2, '0');
            tbReg183.Text = iReg[183].ToString("X").PadLeft(2, '0');
            tbReg184.Text = iReg[184].ToString("X").PadLeft(2, '0');
            tbReg185.Text = iReg[185].ToString("X").PadLeft(2, '0');
            tbReg186.Text = iReg[186].ToString("X").PadLeft(2, '0');
            tbReg187.Text = iReg[187].ToString("X").PadLeft(2, '0');
            tbReg188.Text = iReg[188].ToString("X").PadLeft(2, '0');
            tbReg189.Text = iReg[189].ToString("X").PadLeft(2, '0');
            tbReg190.Text = iReg[190].ToString("X").PadLeft(2, '0');
            tbReg191.Text = iReg[191].ToString("X").PadLeft(2, '0');
            tbReg192.Text = iReg[192].ToString("X").PadLeft(2, '0');
            tbReg193.Text = iReg[193].ToString("X").PadLeft(2, '0');
            tbReg194.Text = iReg[194].ToString("X").PadLeft(2, '0');
            tbReg195.Text = iReg[195].ToString("X").PadLeft(2, '0');
            tbReg196.Text = iReg[196].ToString("X").PadLeft(2, '0');
            tbReg197.Text = iReg[197].ToString("X").PadLeft(2, '0');
            tbReg198.Text = iReg[198].ToString("X").PadLeft(2, '0');
            tbReg199.Text = iReg[199].ToString("X").PadLeft(2, '0');
            tbReg200.Text = iReg[200].ToString("X").PadLeft(2, '0');
            tbReg201.Text = iReg[201].ToString("X").PadLeft(2, '0');
            tbReg202.Text = iReg[202].ToString("X").PadLeft(2, '0');
            tbReg203.Text = iReg[203].ToString("X").PadLeft(2, '0');
            tbReg204.Text = iReg[204].ToString("X").PadLeft(2, '0');
            tbReg205.Text = iReg[205].ToString("X").PadLeft(2, '0');
            tbReg206.Text = iReg[206].ToString("X").PadLeft(2, '0');
            tbReg207.Text = iReg[207].ToString("X").PadLeft(2, '0');
            tbReg208.Text = iReg[208].ToString("X").PadLeft(2, '0');
            tbReg209.Text = iReg[209].ToString("X").PadLeft(2, '0');
            tbReg210.Text = iReg[210].ToString("X").PadLeft(2, '0');
            tbReg211.Text = iReg[211].ToString("X").PadLeft(2, '0');
            tbReg212.Text = iReg[212].ToString("X").PadLeft(2, '0');
            tbReg213.Text = iReg[213].ToString("X").PadLeft(2, '0');
            tbReg214.Text = iReg[214].ToString("X").PadLeft(2, '0');
            tbReg215.Text = iReg[215].ToString("X").PadLeft(2, '0');
            tbReg216.Text = iReg[216].ToString("X").PadLeft(2, '0');
            tbReg217.Text = iReg[217].ToString("X").PadLeft(2, '0');
            tbReg218.Text = iReg[218].ToString("X").PadLeft(2, '0');
            tbReg219.Text = iReg[219].ToString("X").PadLeft(2, '0');
            tbReg220.Text = iReg[220].ToString("X").PadLeft(2, '0');
            tbReg221.Text = iReg[221].ToString("X").PadLeft(2, '0');
            tbReg222.Text = iReg[222].ToString("X").PadLeft(2, '0');
            tbReg223.Text = iReg[223].ToString("X").PadLeft(2, '0');
            tbReg224.Text = iReg[224].ToString("X").PadLeft(2, '0');
            tbReg225.Text = iReg[225].ToString("X").PadLeft(2, '0');
            tbReg226.Text = iReg[226].ToString("X").PadLeft(2, '0');
            tbReg227.Text = iReg[227].ToString("X").PadLeft(2, '0');
            tbReg228.Text = iReg[228].ToString("X").PadLeft(2, '0');
            tbReg229.Text = iReg[229].ToString("X").PadLeft(2, '0');
            tbReg230.Text = iReg[230].ToString("X").PadLeft(2, '0');
            tbReg231.Text = iReg[231].ToString("X").PadLeft(2, '0');
            tbReg232.Text = iReg[232].ToString("X").PadLeft(2, '0');
            tbReg233.Text = iReg[233].ToString("X").PadLeft(2, '0');
            tbReg234.Text = iReg[234].ToString("X").PadLeft(2, '0');
            tbReg235.Text = iReg[235].ToString("X").PadLeft(2, '0');
            tbReg236.Text = iReg[236].ToString("X").PadLeft(2, '0');
            tbReg237.Text = iReg[237].ToString("X").PadLeft(2, '0');
            tbReg238.Text = iReg[238].ToString("X").PadLeft(2, '0');
            tbReg239.Text = iReg[239].ToString("X").PadLeft(2, '0');
            tbReg240.Text = iReg[240].ToString("X").PadLeft(2, '0');
            tbReg241.Text = iReg[241].ToString("X").PadLeft(2, '0');
            tbReg242.Text = iReg[242].ToString("X").PadLeft(2, '0');
            tbReg243.Text = iReg[243].ToString("X").PadLeft(2, '0');
            tbReg244.Text = iReg[244].ToString("X").PadLeft(2, '0');
            tbReg245.Text = iReg[245].ToString("X").PadLeft(2, '0');
            tbReg246.Text = iReg[246].ToString("X").PadLeft(2, '0');
            tbReg247.Text = iReg[247].ToString("X").PadLeft(2, '0');
            tbReg248.Text = iReg[248].ToString("X").PadLeft(2, '0');
            tbReg249.Text = iReg[249].ToString("X").PadLeft(2, '0');
            tbReg250.Text = iReg[250].ToString("X").PadLeft(2, '0');
            tbReg251.Text = iReg[251].ToString("X").PadLeft(2, '0');
            tbReg252.Text = iReg[252].ToString("X").PadLeft(2, '0');
            tbReg253.Text = iReg[253].ToString("X").PadLeft(2, '0');
            tbReg254.Text = iReg[254].ToString("X").PadLeft(2, '0');
            tbReg255.Text = iReg[255].ToString("X").PadLeft(2, '0');

            //EEPROM-Register aktualisieren
            tbEEPROM00.Text = iEEPROM[0].ToString("X").PadLeft(2, '0');
            tbEEPROM01.Text = iEEPROM[1].ToString("X").PadLeft(2, '0');
            tbEEPROM02.Text = iEEPROM[2].ToString("X").PadLeft(2, '0');
            tbEEPROM03.Text = iEEPROM[3].ToString("X").PadLeft(2, '0');
            tbEEPROM04.Text = iEEPROM[4].ToString("X").PadLeft(2, '0');
            tbEEPROM05.Text = iEEPROM[5].ToString("X").PadLeft(2, '0');
            tbEEPROM06.Text = iEEPROM[6].ToString("X").PadLeft(2, '0');
            tbEEPROM07.Text = iEEPROM[7].ToString("X").PadLeft(2, '0');
            tbEEPROM08.Text = iEEPROM[8].ToString("X").PadLeft(2, '0');
            tbEEPROM09.Text = iEEPROM[9].ToString("X").PadLeft(2, '0');
            tbEEPROM10.Text = iEEPROM[10].ToString("X").PadLeft(2, '0');
            tbEEPROM11.Text = iEEPROM[11].ToString("X").PadLeft(2, '0');
            tbEEPROM12.Text = iEEPROM[12].ToString("X").PadLeft(2, '0');
            tbEEPROM13.Text = iEEPROM[13].ToString("X").PadLeft(2, '0');
            tbEEPROM14.Text = iEEPROM[14].ToString("X").PadLeft(2, '0');
            tbEEPROM15.Text = iEEPROM[15].ToString("X").PadLeft(2, '0');
            tbEEPROM16.Text = iEEPROM[16].ToString("X").PadLeft(2, '0');
            tbEEPROM17.Text = iEEPROM[17].ToString("X").PadLeft(2, '0');
            tbEEPROM18.Text = iEEPROM[18].ToString("X").PadLeft(2, '0');
            tbEEPROM19.Text = iEEPROM[19].ToString("X").PadLeft(2, '0');
            tbEEPROM20.Text = iEEPROM[20].ToString("X").PadLeft(2, '0');
            tbEEPROM21.Text = iEEPROM[21].ToString("X").PadLeft(2, '0');
            tbEEPROM22.Text = iEEPROM[22].ToString("X").PadLeft(2, '0');
            tbEEPROM23.Text = iEEPROM[23].ToString("X").PadLeft(2, '0');
            tbEEPROM24.Text = iEEPROM[24].ToString("X").PadLeft(2, '0');
            tbEEPROM25.Text = iEEPROM[25].ToString("X").PadLeft(2, '0');
            tbEEPROM26.Text = iEEPROM[26].ToString("X").PadLeft(2, '0');
            tbEEPROM27.Text = iEEPROM[27].ToString("X").PadLeft(2, '0');
            tbEEPROM28.Text = iEEPROM[28].ToString("X").PadLeft(2, '0');
            tbEEPROM29.Text = iEEPROM[29].ToString("X").PadLeft(2, '0');
            tbEEPROM30.Text = iEEPROM[30].ToString("X").PadLeft(2, '0');
            tbEEPROM31.Text = iEEPROM[31].ToString("X").PadLeft(2, '0');
            tbEEPROM32.Text = iEEPROM[32].ToString("X").PadLeft(2, '0');
            tbEEPROM33.Text = iEEPROM[33].ToString("X").PadLeft(2, '0');
            tbEEPROM34.Text = iEEPROM[34].ToString("X").PadLeft(2, '0');
            tbEEPROM35.Text = iEEPROM[35].ToString("X").PadLeft(2, '0');
            tbEEPROM36.Text = iEEPROM[36].ToString("X").PadLeft(2, '0');
            tbEEPROM37.Text = iEEPROM[37].ToString("X").PadLeft(2, '0');
            tbEEPROM38.Text = iEEPROM[38].ToString("X").PadLeft(2, '0');
            tbEEPROM39.Text = iEEPROM[39].ToString("X").PadLeft(2, '0');
            tbEEPROM40.Text = iEEPROM[40].ToString("X").PadLeft(2, '0');
            tbEEPROM41.Text = iEEPROM[41].ToString("X").PadLeft(2, '0');
            tbEEPROM42.Text = iEEPROM[42].ToString("X").PadLeft(2, '0');
            tbEEPROM43.Text = iEEPROM[43].ToString("X").PadLeft(2, '0');
            tbEEPROM44.Text = iEEPROM[44].ToString("X").PadLeft(2, '0');
            tbEEPROM45.Text = iEEPROM[45].ToString("X").PadLeft(2, '0');
            tbEEPROM46.Text = iEEPROM[46].ToString("X").PadLeft(2, '0');
            tbEEPROM47.Text = iEEPROM[47].ToString("X").PadLeft(2, '0');
            tbEEPROM48.Text = iEEPROM[48].ToString("X").PadLeft(2, '0');
            tbEEPROM49.Text = iEEPROM[49].ToString("X").PadLeft(2, '0');
            tbEEPROM50.Text = iEEPROM[50].ToString("X").PadLeft(2, '0');
            tbEEPROM51.Text = iEEPROM[51].ToString("X").PadLeft(2, '0');
            tbEEPROM52.Text = iEEPROM[52].ToString("X").PadLeft(2, '0');
            tbEEPROM53.Text = iEEPROM[53].ToString("X").PadLeft(2, '0');
            tbEEPROM54.Text = iEEPROM[54].ToString("X").PadLeft(2, '0');
            tbEEPROM55.Text = iEEPROM[55].ToString("X").PadLeft(2, '0');
            tbEEPROM56.Text = iEEPROM[56].ToString("X").PadLeft(2, '0');
            tbEEPROM57.Text = iEEPROM[57].ToString("X").PadLeft(2, '0');
            tbEEPROM58.Text = iEEPROM[58].ToString("X").PadLeft(2, '0');
            tbEEPROM59.Text = iEEPROM[59].ToString("X").PadLeft(2, '0');
            tbEEPROM60.Text = iEEPROM[60].ToString("X").PadLeft(2, '0');
            tbEEPROM61.Text = iEEPROM[61].ToString("X").PadLeft(2, '0');
            tbEEPROM62.Text = iEEPROM[62].ToString("X").PadLeft(2, '0');
            tbEEPROM63.Text = iEEPROM[63].ToString("X").PadLeft(2, '0');

            //RegStatusupdate fuer GUI

            if ((iReg[0x03] & 0x01) == 0x01)
            {
                tStatus0.Text = "1";
            }
            else
            {
                tStatus0.Text = "0";
            }
            if ((iReg[0x03] & 0x02) == 0x02)
            {
                tStatus1.Text = "1";
            }
            else
            {
                tStatus1.Text = "0";
            }

            if ((iReg[0x03] & 0x04) == 0x04)
            {
                tStatus2.Text = "1";
            }
            else
            {
                tStatus2.Text = "0";
            }
            if ((iReg[0x03] & 0x08) == 0x08)
            {
                tStatus3.Text = "1";
            }
            else
            {
                tStatus3.Text = "0";
            }
            if ((iReg[0x03] & 0x10) == 0x10)
            {
                tStatus4.Text = "1";
            }
            else
            {
                tStatus4.Text = "0";
            }
            if ((iReg[0x03] & 0x20) == 0x20)
            {
                tStatus5.Text = "1";
            }
            else
            {
                tStatus5.Text = "0";
            }
            if ((iReg[0x03] & 0x40) == 0x40)
            {
                tStatus6.Text = "1";
            }
            else
            {
                tStatus6.Text = "0";
            }
            if ((iReg[0x03] & 0x01) == 0x01)
            {
                tStatus0.Text = "1";
            }
            else
            {
                tStatus0.Text = "0";
            }
            if ((iReg[0x03] & 0x02) == 0x02)
            {
                tStatus1.Text = "1";
            }
            else
            {
                tStatus1.Text = "0";
            }

            if ((iReg[0x03] & 0x04) == 0x04)
            {
                tStatus2.Text = "1";
            }
            else
            {
                tStatus2.Text = "0";
            }
            if ((iReg[0x03] & 0x08) == 0x08)
            {
                tStatus3.Text = "1";
            }
            else
            {
                tStatus3.Text = "0";
            }
            if ((iReg[0x03] & 0x10) == 0x10)
            {
                tStatus4.Text = "1";
            }
            else
            {
                tStatus4.Text = "0";
            }
            if ((iReg[0x03] & 0x20) == 0x20)
            {
                tStatus5.Text = "1";
            }
            else
            {
                tStatus5.Text = "0";
            }
            if ((iReg[0x03] & 0x40) == 0x40)
            {
                tStatus6.Text = "1";
            }
            else
            {
                tStatus6.Text = "0";
            }
            //PortRA
            if ((iReg[0x05] & 0x01) == 0x01)
            {
                tRA0.Text = "1";
            }
            else
            {
                tRA0.Text = "0";
            }
            if ((iReg[0x05] & 0x02) == 0x02)
            {
                tRA1.Text = "1";
            }
            else
            {
                tRA1.Text = "0";
            }
            if ((iReg[0x05] & 0x04) == 0x04)
            {
                tRA2.Text = "1";
            }
            else
            {
                tRA2.Text = "0";
            }
            if ((iReg[0x05] & 0x08) == 0x08)
            {
                tRA3.Text = "1";
            }
            else
            {
                tRA3.Text = "0";
            }
            if ((iReg[0x05] & 0x10) == 0x10)
            {
                tRA4.Text = "1";
            }
            else
            {
                tRA4.Text = "0";
            }

            //PortRB
            if ((iReg[0x06] & 0x01) == 0x01)
            {
                tRB0.Text = "1";
            }
            else
            {
                tRB0.Text = "0";
            }
            if ((iReg[0x06] & 0x02) == 0x02)
            {
                tRB1.Text = "1";
            }
            else
            {
                tRB1.Text = "0";
            }
            if ((iReg[0x06] & 0x04) == 0x04)
            {
                tRB2.Text = "1";
            }
            else
            {
                tRB2.Text = "0";
            }
            if ((iReg[0x06] & 0x08) == 0x08)
            {
                tRB3.Text = "1";
            }
            else
            {
                tRB3.Text = "0";
            }
            if ((iReg[0x06] & 0x10) == 0x10)
            {
                tRB4.Text = "1";
            }
            else
            {
                tRB4.Text = "0";
            }
            if ((iReg[0x06] & 0x20) == 0x20)
            {
                tRB5.Text = "1";
            }
            else
            {
                tRB5.Text = "0";
            }
            if ((iReg[0x06] & 0x40) == 0x40)
            {
                tRB6.Text = "1";
            }
            else
            {
                tRB6.Text = "0";
            }
            if ((iReg[0x06] & 0x80) == 0x80)
            {
                tRB7.Text = "1";
            }
            else
            {
                tRB7.Text = "0";
            }
            //OptionRegister

            if ((iReg[0x81] & 0x01) == 0x01)
            {
                tbOption0.Text = "1";
            }
            else
            {
                tbOption0.Text = "0";
            }
            if ((iReg[0x81] & 0x02) == 0x02)
            {
                tbOption1.Text = "1";
            }
            else
            {
                tbOption1.Text = "0";
            }
            if ((iReg[0x81] & 0x04) == 0x04)
            {
                tbOption2.Text = "1";
            }
            else
            {
                tbOption2.Text = "0";
            }
            if ((iReg[0x81] & 0x08) == 0x08)
            {
                tbOption3.Text = "1";
            }
            else
            {
                tbOption3.Text = "0";
            }
            if ((iReg[0x81] & 0x10) == 0x10)
            {
                tbOption4.Text = "1";
            }
            else
            {
                tbOption4.Text = "0";
            }
            if ((iReg[0x81] & 0x20) == 0x20)
            {
                tbOption5.Text = "1";
            }
            else
            {
                tbOption5.Text = "0";
            }
            if ((iReg[0x81] & 0x40) == 0x40)
            {
                tbOption6.Text = "1";
            }
            else
            {
                tbOption6.Text = "0";
            }
            if ((iReg[0x81] & 0x80) == 0x80)
            {
                tbOption7.Text = "1";
            }
            else
            {
                tbOption7.Text = "0";
            }

            //TRISA
            if ((iReg[0x85] & 0x01) == 0x01)
            {
                tbTrisA0.Text = "i";
            }
            else
            {
                tbTrisA0.Text = "o";
            }
            if ((iReg[0x85] & 0x02) == 0x02)
            {
                tbTrisA1.Text = "i";
            }
            else
            {
                tbTrisA1.Text = "o";
            }
            if ((iReg[0x85] & 0x04) == 0x04)
            {
                tbTrisA2.Text = "i";
            }
            else
            {
                tbTrisA2.Text = "o";
            }
            if ((iReg[0x85] & 0x08) == 0x08)
            {
                tbTrisA3.Text = "i";
            }
            else
            {
                tbTrisA3.Text = "o";
            }
            if ((iReg[0x85] & 0x10) == 0x10)
            {
                tbTrisA4.Text = "i";
            }
            else
            {
                tbTrisA4.Text = "o";
            }
            //TRISB
            if ((iReg[0x86] & 0x01) == 0x01)
            {
                tbTrisB0.Text = "i";
            }
            else
            {
                tbTrisB0.Text = "o";
            }
            if ((iReg[0x86] & 0x02) == 0x02)
            {
                tbTrisB1.Text = "i";
            }
            else
            {
                tbTrisB1.Text = "o";
            }
            if ((iReg[0x86] & 0x04) == 0x04)
            {
                tbTrisB2.Text = "i";
            }
            else
            {
                tbTrisB2.Text = "o";
            }
            if ((iReg[0x86] & 0x08) == 0x08)
            {
                tbTrisB3.Text = "i";
            }
            else
            {
                tbTrisB3.Text = "o";
            }
            if ((iReg[0x86] & 0x10) == 0x10)
            {
                tbTrisB4.Text = "i";
            }
            else
            {
                tbTrisB4.Text = "o";
            }
            if ((iReg[0x86] & 0x20) == 0x20)
            {
                tbTrisB5.Text = "i";
            }
            else
            {
                tbTrisB5.Text = "o";
            }
            if ((iReg[0x86] & 0x40) == 0x40)
            {
                tbTrisB6.Text = "i";
            }
            else
            {
                tbTrisB6.Text = "o";
            }
            if ((iReg[0x86] & 0x80) == 0x80)
            {
                tbTrisB7.Text = "i";
            }
            else
            {
                tbTrisB7.Text = "o";
            }

            //InterruptRegister
            if ((iReg[0x0B] & 0x01) == 0x01)
            {
                tbInt0.Text = "1";
            }
            else
            {
                tbInt0.Text = "0";
            }
            if ((iReg[0x0B] & 0x02) == 0x02)
            {
                tbInt1.Text = "1";
            }
            else
            {
                tbInt1.Text = "0";
            }
            if ((iReg[0x0B] & 0x04) == 0x04)
            {
                tbInt2.Text = "1";
            }
            else
            {
                tbInt2.Text = "0";
            }
            if ((iReg[0x0B] & 0x08) == 0x08)
            {
                tbInt3.Text = "1";
            }
            else
            {
                tbInt3.Text = "0";
            }
            if ((iReg[0x0B] & 0x10) == 0x10)
            {
                tbInt4.Text = "1";
            }
            else
            {
                tbInt4.Text = "0";
            }
            if ((iReg[0x0B] & 0x20) == 0x20)
            {
                tbInt5.Text = "1";
            }
            else
            {
                tbInt5.Text = "0";
            }
            if ((iReg[0x0B] & 0x40) == 0x40)
            {
                tbInt6.Text = "1";
            }
            else
            {
                tbInt6.Text = "0";
            }
            if ((iReg[0x0B] & 0x80) == 0x80)
            {
                tbInt7.Text = "1";
            }
            else
            {
                tbInt7.Text = "0";
            }
            //EEPROM-Register
            if ((iReg[0x88] & 0x01) == 0x01)
            {
                tbEECON0.Text = "1";
            }
            else
            {
                tbEECON0.Text = "0";
            }
            if ((iReg[0x88] & 0x02) == 0x02)
            {
                tbEECON1.Text = "1";
            }
            else
            {
                tbEECON1.Text = "0";
            }
            if ((iReg[0x88] & 0x04) == 0x04)
            {
                tbEECON2.Text = "1";
            }
            else
            {
                tbEECON2.Text = "0";
            }
            if ((iReg[0x88] & 0x08) == 0x08)
            {
                tbEECON3.Text = "1";
            }
            else
            {
                tbEECON3.Text = "0";
            }
            if ((iReg[0x88] & 0x10) == 0x10)
            {
                tbEECON4.Text = "1";
            }
            else
            {
                tbEECON4.Text = "0";
            }

            iPrescalerValue = Convert.ToInt32( Math.Pow(2, 1 + (iReg[0x81] & 0x07) ) );
            if ((iReg[0x81] & 0x08) == 0x08)
            {
                iPrescalerValue = (iPrescalerValue / 2);
                tbPSCAssign.Text = "WDT";
            }
            else
            {
                tbPSCAssign.Text = "TMR0";
            }
            tbPrescaler.Text = "1:" + Convert.ToString( iPrescalerValue );


            //Stack anzeigen mithilfe eines temporären Stacks
            Stack<int> tempStack = new Stack<int>();
            string[] sStack = new string[8] { "  ", "  ", "  ", "  ", "  ", "  ", "  ", "  " };

            while (stack.Count > 0)
            {
                if (stack.Count == 1)
                {
                    try
                    {
                        sStack[0] = stack.Peek().ToString("X");
                    }
                    catch (Exception ex)
                    {
                    }
                }
                if (stack.Count == 2)
                {
                    try
                    {
                        sStack[1] = stack.Peek().ToString("X");
                    }
                    catch (Exception ex)
                    {
                    }
                }
                if (stack.Count == 3)
                {
                    try
                    {
                        sStack[2] = stack.Peek().ToString("X");
                    }
                    catch (Exception ex)
                    {
                    }
                }
                if (stack.Count == 4)
                {
                    try
                    {
                        sStack[3] = stack.Peek().ToString("X");
                    }
                    catch (Exception ex)
                    {
                    }
                }
                if (stack.Count == 5)
                {
                    try
                    {
                        sStack[4] = stack.Peek().ToString("X");
                    }
                    catch (Exception ex)
                    {
                    }
                }
                if (stack.Count == 6)
                {
                    try
                    {
                        sStack[5] = stack.Peek().ToString("X");
                    }
                    catch (Exception ex)
                    {
                    }
                }
                if (stack.Count == 7)
                {
                    try
                    {
                        sStack[6] = stack.Peek().ToString("X");
                    }
                    catch (Exception ex)
                    {
                    }
                }
                if (stack.Count == 8)
                {
                    try
                    {
                        sStack[7] = stack.Peek().ToString("X");
                    }
                    catch (Exception ex)
                    {
                    }
                }

                tempStack.Push(stack.Pop());
            }
            while (tempStack.Count > 0)
            {
                stack.Push(tempStack.Pop());
            }

            lbStack0.Text = sStack[0];
            lbStack1.Text = sStack[1];
            lbStack2.Text = sStack[2];
            lbStack3.Text = sStack[3];
            lbStack4.Text = sStack[4];
            lbStack5.Text = sStack[5];
            lbStack6.Text = sStack[6];
            lbStack7.Text = sStack[7];
        }

        /*********************************************************************/
        /**   enableEEPReg
        **
        **  Alle EEPROM-Register Felder werden auf Enabled gesetzt, nachdem eine
        **  *.eep Datei geöffnet wurde
        **
        **  Ret: void
        **
        **************************************************************************/
        private delegate void enableEEPRegDelegate();
        private void enableEEPReg()
        {
            if (InvokeRequired)
            {
                var invokeVar = new enableEEPRegDelegate(enableEEPReg);
                Invoke(invokeVar);
            }
            else
            {
                tbEEPROM00.Enabled = true;
                tbEEPROM01.Enabled = true;
                tbEEPROM02.Enabled = true;
                tbEEPROM03.Enabled = true;
                tbEEPROM04.Enabled = true;
                tbEEPROM05.Enabled = true;
                tbEEPROM06.Enabled = true;
                tbEEPROM07.Enabled = true;
                tbEEPROM08.Enabled = true;
                tbEEPROM09.Enabled = true;
                tbEEPROM10.Enabled = true;
                tbEEPROM11.Enabled = true;
                tbEEPROM12.Enabled = true;
                tbEEPROM13.Enabled = true;
                tbEEPROM14.Enabled = true;
                tbEEPROM15.Enabled = true;
                tbEEPROM16.Enabled = true;
                tbEEPROM17.Enabled = true;
                tbEEPROM18.Enabled = true;
                tbEEPROM19.Enabled = true;
                tbEEPROM20.Enabled = true;
                tbEEPROM21.Enabled = true;
                tbEEPROM22.Enabled = true;
                tbEEPROM23.Enabled = true;
                tbEEPROM24.Enabled = true;
                tbEEPROM25.Enabled = true;
                tbEEPROM26.Enabled = true;
                tbEEPROM27.Enabled = true;
                tbEEPROM28.Enabled = true;
                tbEEPROM29.Enabled = true;
                tbEEPROM30.Enabled = true;
                tbEEPROM31.Enabled = true;
                tbEEPROM32.Enabled = true;
                tbEEPROM33.Enabled = true;
                tbEEPROM34.Enabled = true;
                tbEEPROM35.Enabled = true;
                tbEEPROM36.Enabled = true;
                tbEEPROM37.Enabled = true;
                tbEEPROM38.Enabled = true;
                tbEEPROM39.Enabled = true;
                tbEEPROM40.Enabled = true;
                tbEEPROM41.Enabled = true;
                tbEEPROM42.Enabled = true;
                tbEEPROM43.Enabled = true;
                tbEEPROM44.Enabled = true;
                tbEEPROM45.Enabled = true;
                tbEEPROM46.Enabled = true;
                tbEEPROM47.Enabled = true;
                tbEEPROM48.Enabled = true;
                tbEEPROM49.Enabled = true;
                tbEEPROM50.Enabled = true;
                tbEEPROM51.Enabled = true;
                tbEEPROM52.Enabled = true;
                tbEEPROM53.Enabled = true;
                tbEEPROM54.Enabled = true;
                tbEEPROM55.Enabled = true;
                tbEEPROM56.Enabled = true;
                tbEEPROM57.Enabled = true;
                tbEEPROM58.Enabled = true;
                tbEEPROM59.Enabled = true;
                tbEEPROM60.Enabled = true;
                tbEEPROM61.Enabled = true;
                tbEEPROM62.Enabled = true;
                tbEEPROM63.Enabled = true;
            }
        }
    }
}
